package com.nike.amoeba.api

import android.os.Bundle
import androidx.navigation.NavController
import androidx.navigation.NavOptions
import com.blankj.utilcode.util.ActivityUtils
import com.google.gson.Gson
import com.nike.amoeba.MainActivity
import com.nike.amoeba.R
import com.nike.amoeba.bean.DataBean
import com.nike.amoeba.bean.db.AssetBean
import com.nike.amoeba.ext.WAREHOUSE_RU_TYPE
import com.nike.amoeba.ui.act.LoginAct
import com.nike.amoeba.ui.act.ZxingAct
import me.hgj.jetpackmvvm.ext.navigateAction


/**
 * Created by Administrator on 2017/2/22.
 */

class UIHelper private constructor() {

    init {
        throw UnsupportedOperationException("u can't instantiate me...")
    }


    companion object {

        val navOptions = NavOptions.Builder()
            .setEnterAnim(R.anim.slide_in_right)  // 设置进入动画
            .setExitAnim(R.anim.slide_out_left)  // 设置退出动画
            .setPopEnterAnim(R.anim.slide_in_left)  // 设置返回动画
            .setPopExitAnim(R.anim.slide_out_right)  // 设置返回退出动画
            .build()

        fun startMainAct() {
            ActivityUtils.startActivity(MainActivity::class.java)
        }

        /**
         *  二维码
         */
        fun startZxingAct(type: Int) {
            val bundle = Bundle()
            bundle.putInt("type", type)
            ActivityUtils.startActivity(bundle, ZxingAct::class.java)
        }

        /**
         *  登录
         */
        fun startLoginAct() {
            ActivityUtils.startActivity(LoginAct::class.java)
        }

        /**
         *  设置
         */
        fun startSettingFrg(nav: NavController) {
            nav.navigateAction(R.id.action_loginfragment_to_settingFrg)
        }

        /**
         *  下载
         */
        fun startDownloadFrg(nav: NavController) {
            nav.navigateAction(R.id.downloadFrg)
        }

        /**
         *  RFID 列表
         */
        fun startAssetFrg(nav: NavController, orderId: String, code: String?) {
            nav.navigateAction(R.id.action_takeAssetFrg_to_assetFrg, Bundle().apply {
                putString("orderId", orderId)
                putString("code", code)
            })
        }

        /**
         *  库存RFID 列表
         */
        fun startTaskStockListFrg(nav: NavController, orderId: String, code: String?) {
            nav.navigateAction(R.id.action_taskStockFrg_to_taskStockListFrg, Bundle().apply {
                putString("orderId", orderId)
                putString("code", code)
            })
        }

        /**
         *  库存调整子列表
         */
        fun startStockAdjListFrg(nav: NavController, orderId: String, assetNo: String?, code: String?) {
            nav.navigateAction(R.id.action_stockAdjustFrg_to_stockAdjListFrg, Bundle().apply {
                putString("orderId", orderId)
                putString("assetNo", assetNo)
                putString("code", code)
            })
        }

        /**
         *  库存RFID EPC列表
         */
        fun startTaskStockEpcFrg(
            nav: NavController,
            orderId: String,
            batchNo: String,
            code: String?
        ) {
            nav.navigateAction(R.id.action_taskStockListFrg_to_taskStockEpcFrg, Bundle().apply {
                putString("orderId", orderId)
                putString("batchNo", batchNo)
                putString("code", code)
            })
        }

        /**
         *  资产盘点订单
         */
        fun startTaskAssetFrg(nav: NavController, code: String?, title: String?) {
            nav.navigate(R.id.takeAssetFrg, Bundle().apply {
                putString("code", code)
                putString("title", title)
            })
        }

        /**
         *  通用查看详细
         */
        fun startStockTextFrg(nav: NavController, content: String?, AssetNo: String?) {
            nav.navigate(R.id.action_stockManageListFrg_to_assetTextFrg, Bundle().apply {
                putString("bean", content)
                putString("assetNo", AssetNo)
            })
        }
        fun startStockTextFrg2(nav: NavController, content: String?, AssetNo: String?) {
            nav.navigate(R.id.action_taskStockListFrg_to_stockTextFrg, Bundle().apply {
                putString("bean", content)
                putString("assetNo", AssetNo)
            })
        }

        /**
         *  库存盘点订单
         */
        fun startTaskStockFrg(nav: NavController, code: String?, title: String?) {
            nav.navigateAction(R.id.taskStockFrg, Bundle().apply {
                putString("code", code)
                putString("title", title)
            })
        }

        /**
         *  RFID 详情
         */
        fun startAssetDetailsFrg(nav: NavController, bean: AssetBean) {
            nav.navigateAction(R.id.action_assetFrg_to_assetDetailsFrg, Bundle().apply {
                putString("bean", Gson().toJson(bean))
            })
        }

        /**
         *  上传
         */
        fun starUploadFrg(nav: NavController) {
            nav.navigateAction(R.id.uploadFrg)
            /*nav.navigate(
                R.id.uploadFrg,
                null,
                NavOptions.Builder()
                    .setPopUpTo(R.id.uploadFrg, false) // 设置为 true 以包含当前的 Fragment
                    .build()
            )*/
        }

        /**
         *  RFID 配置
         */
        fun starRfidConfigFrg(nav: NavController) {
            nav.navigateAction(R.id.configFrg)
        }

        /**
         *  库存调整
         */
        fun starStockAdjustFrg(nav: NavController, code: String?, title: String?) {
            nav.navigateAction(R.id.stockAdjustFrg, Bundle().apply {
                putString("code", code)
                putString("title", title)
            })
        }

        /**
         *  出入库列表管理
         */
        fun starStockManageParentFrg(nav: NavController, code: String?, title: String?) {
            nav.navigate(R.id.stockManageParentFrg, Bundle().apply {
                putString("code", code)
                putString("title", title)
            })
        }

        /**
         *  出入库详情
         */
        fun starStockManageListFrg(
            nav: NavController,
            batchNo: String?,
            stockType: Int,
            code: String?
        ) {
            nav.navigateAction(R.id.action_stockManageParentFrg_to_stockManageListFrg, Bundle().apply {
                putString("batchNo", batchNo)
                putInt("stockType", stockType)
                putString("code", code)
            })
        }

        /**
         *  库存盘点
         */
/*        fun starStockEpcFrg(
            nav: NavController,
            batchNo: String?,
            roNo: String,
            assetNo: String?,
            stockType: Int,
            code: String?
        ) {
            nav.navigateAction(if (stockType == WAREHOUSE_RU_TYPE) R.id.action_stockManageListFrg_to_stockRuEpcFrg else R.id.action_stockManageListFrg_to_stockChuEpcFrg, Bundle().apply {
                putString("batchNo", batchNo)
                putString("ARoNo", roNo)
                putString("assetNo", assetNo)
                putInt("stockType", stockType)
                putString("code", code)
            })
        }*/
        fun starStockEpcFrg(
            nav: NavController,
            batchNo: String?,
            bean: DataBean,
            stockType: Int,
            code: String?
        ) {
            nav.navigateAction(if (stockType == WAREHOUSE_RU_TYPE) R.id.action_stockManageListFrg_to_stockRuEpcFrg else R.id.action_stockManageListFrg_to_stockChuEpcFrg, Bundle().apply {
                putString("batchNo", batchNo)
                putString("bean", Gson().toJson(bean))
                putInt("stockType", stockType)
                putString("code", code)
            })
        }

        fun onClearAllFrg(nav: NavController){
            /*nav.graph.forEach {
                nav.popBackStack(it.id, true)
            }*/
//            val navOptions = NavOptions.Builder()
//                .setPopUpTo(nav.graph.startDestination, true)
//                .build()
//            nav.popBackStack(nav.graph.startDestination, true)
        }

    }
}

